package org.soc.timesheet.server.domain.service;

import java.util.List;

import org.soc.timesheet.custom.domain.filters.UserFilter;
import org.soc.timesheet.domain.Users;
import org.soc.timesheet.domain.repository.UsersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UsersServiceImpl implements UsersService {

	@Autowired
    UsersRepository usersRepository;

	public long countAllUserses() {
        return usersRepository.count();
    }

	public void deleteUsers(Users users) {
        usersRepository.delete(users);
    }

	public Users findUsers(Integer id) {
        return usersRepository.findOne(id);
    }

	public List<Users> findAllUserses() {
        return usersRepository.findAll();
    }

	public List<Users> findUsersEntries(int firstResult, int maxResults) {
        return usersRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public Users saveUsers(Users users) {
        return usersRepository.save(users); 
    }

	public Users updateUsers(Users users) {
        return usersRepository.save(users);
    }

	@Override
	public Page<Users> findAll(PageRequest pageRequest) {
		// TODO Auto-generated method stub
		return usersRepository.findAll(pageRequest);
	}

	@Override
	public Page<Users> findByFilters(UserFilter filter,
			PageRequest pageRequest) {
		// TODO Auto-generated method stub
		return usersRepository.findAll(filter, pageRequest);
	}

	@Override
	public Users findByLogin(String username) {
		// TODO Auto-generated method stub
		return usersRepository.findByLogin(username);
	}
}
